#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>


char g_command[1024];
int GetCommand()
{
    printf("[minishell@localhost minishell]");
    fflush(stdout);
    memset(g_command,'\0',sizeof(g_command));
    if(fgets(g_command,sizeof(g_command)-1,stdin)==NULL){
        perror("fgets error");
        return -1;
    }
    printf("%s\n",g_command);
    return 0;
}


int DealCommand(char *command)
{
    int argc = 0;
    char *argv[1024] = {0};
    while(*command)
    {
        if(!isspace(*command) && *command !='\0'){
            argv[argc] = command;
            argc++;
            while(!isspace(*command) && *command !='\0'){
                command++;
            }
            *command = '\0';
        }
        command++;
    }

    argv[argc]  = NULL;
    for(int i=0;i<argc;i++){
        printf("%d:%s\n",i,argv[i]);
    }
}


int main()
{
    while(1){
        if(GetCommand()==-1){
            continue;
        }
        DealCommand(g_command);
    }
    return 0;
}